/* EasyWay Game Engine
 * Copyright (C) 2006 Daniele Paggi.
 *  
 * Written by: 2006 Daniele Paggi<dshnt@hotmail.com>
 *   
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.easyway.lists;

import java.io.Serializable;

import org.easyway.interfaces.extended.ILoopable;
import org.easyway.interfaces.sprites.ICollisionable;

/**
 * mangage the collisions<br>
 * self used by the game engine
 */
public class CollisionableLoopList extends BaseList<ICollisionable> implements
		ILoopable,
		Serializable {
	static final long serialVersionUID = 104;

	/** costruttore */
	public CollisionableLoopList() {
		super();
	}

	// -----------------------------------------

	/** loops all sprites */
	public void loop() {

		ICollisionable spr;
		// Vector used = new Vector();
		for (indexScan = size() - 1; indexScan >= 0; indexScan--) {
			spr = get(indexScan);
			if (spr == null)
				continue;

			remove(indexScan);
			// if (spr.getCollisionList().size()==0) {
			// new Exception().printStackTrace();
			// }
			spr.onCollision();
			spr.setAddedToCollisionList(false);
			spr.getCollisionList().clear();// .removeAll();
		}
		indexScan = -1;
		// used = null;
	}

	// public void resetCollisioni() {
	// ICollisionable temp;
	// for (int i = 0; i < size(); i++) {
	// if ((temp = (ICollisionable) get(i)) != null) {
	// temp.getCollisionList().removeAll();
	// }
	// }
	// }

}
